#include "../Comm/comm.hpp"
#include "cmp_and_run.hpp"
#include "../Comm/httplib.h"
using namespace ns_compile_and_run;
using namespace httplib;
/****
 * 使用cpp-httplib库将服务对外提供
 * 
 * 
*/
void  Usage(std::string proc)
{
    std::cout<<"Usage: "<<"\n\t"<<proc<<" port"<<std::endl;
}
int main(int argc,char* argv[])
{
    if(argc !=2)
    {
        Usage(argv[0]);
        return 1;
    }
    Server cr_ser;
    cr_ser.Post("/cmp_and_run",[](const Request& req,Response& res){
        //用户使用json串进行服务请求
        std::string in_json = req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            CompileAndRun::Start(in_json,&out_json);
            res.set_content(out_json,"application/json;charset=utf-8");
        }

    });
    cr_ser.listen("0.0.0.0",atoi(argv[1]));
    return 0;
}